import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

public class FuncIntExample {
    public static void main(String[] args) {
        Supplier<String> expensiveObjectSupplier = () -> {
            System.out.println("正在创建耗时对象...");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "一个非常耗时的对象";
        };
        System.out.println("程序开始...");
        String result = expensiveObjectSupplier.get();
        System.out.println("获取到的对象是：" + result);
//        List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
//        Function<String, Integer> stringLength = String::length;
//        List<Integer> lengths = names.stream()
//                .map(stringLength)
//                .toList();
//        System.out.println("原始字符串：" + names);
//        System.out.println("字符串长度：" + lengths);
//        Consumer<String> stringPrinter = str -> System.out.println("打印："+ str);
//        names.stream().forEach(stringPrinter);
//        List<Integer> numbers = List.of(1, 2, 3, 4, 5, 6);
//
//        Predicate<Integer> isEven = num -> num % 2 == 0;
//
//        List<Integer> evenNumbers = numbers.stream()
//                .filter(isEven)
//                .toList();
//
//        System.out.println("原始数字：" + numbers);
//        System.out.println("所有偶数：" + evenNumbers);
//
//        Predicate<Integer> isGreaterThan5 = num -> num > 5;
//
//        List<Integer> filteredNumbers = numbers.stream()
//                .filter(isEven.and(isGreaterThan5))
//                .toList();
//        System.out.println("大于5的偶数：" + filteredNumbers);

    }
}
